

###########################################################################
########## Asia Pacific		###############
###########################################################################

data <- read.csv("UNHCR_Data_08052016.csv", sep=",", header=TRUE)
data <- data[data$region=="Asia-Pacific",]
data <- data[data$candidate==1,]
data <- data[data$losing_candidate!=1,]

myvars <- c("year","latentmean")
data1 <- data[myvars]
data1 <- na.omit(data1)
dim(data)

win2006 <- data1[data1$year==2006,]
win2007 <- data1[data1$year==2007,]
win2008 <- data1[data1$year==2008,]
win2009 <- data1[data1$year==2009,]
win2010 <- data1[data1$year==2010,]
win2011 <- data1[data1$year==2011,]
win2012 <- data1[data1$year==2012,]

w2006 <- mean(win2006$latentmean) 
w2007 <- mean(win2007$latentmean) 
w2008 <- mean(win2008$latentmean) 
w2009 <- mean(win2009$latentmean) 
w2010 <- mean(win2010$latentmean) 
w2011 <- mean(win2011$latentmean) 
w2012 <- mean(win2012$latentmean) 


data <- read.csv("UNHCR_Data_08052016.csv", sep=",", header=TRUE)
data <- data[data$region=="Asia-Pacific",]
data <- data[data$candidate==1,]
data <- data[data$losing_candidate==1,]
myvars <- c("year","latentmean")
data1 <- data[myvars]
data1 <- na.omit(data1)
dim(data)


los2006 <- data1[data1$year==2006,]
los2007 <- data1[data1$year==2007,]
los2008 <- data1[data1$year==2008,]
los2009 <- data1[data1$year==2009,]
los2010 <- data1[data1$year==2010,]
los2011 <- data1[data1$year==2011,]
los2012 <- data1[data1$year==2012,]


l2006 <- mean(los2006$latentmean) 
l2007 <- mean(los2007$latentmean) 
l2008 <- mean(los2008$latentmean) 
l2009 <- mean(los2009$latentmean) 
l2010 <- mean(los2010$latentmean) 
l2011 <- mean(los2011$latentmean) 
l2012 <- mean(los2012$latentmean) 




adjust <- 0.25
y1 <- c(w2006,w2007,w2008,w2009,w2010,w2011,w2012)
x1 <- c(2006:2012)

y2 <- c(l2006,l2007,l2008,l2009,l2010,l2011,l2012)
x2 <- c(2006:2012)

par(mar=c(4,4,3,2),xpd=FALSE,mfrow=c(2,1),oma=c(3,0,0,0),xpd=TRUE)
plot(x1,y1,xlab="Election",xlim=c(2006,2012),ylim=c(-1.5,1.5),pch=19,col="dodgerblue",frame.plot=T,axes=F,ylab="Human Rights Score",main="Asia-Pacific")
points(x2,y2,col="red",pch=4,lwd=5)


x.axis <- c(2006:2012)
X <- c("'06","'07","'08","'09","'10","'11","'12")
axis(1,at = x.axis,labels=X)

y.axis <- c(-1.5,0,1.5)
Y <- c("-1.5","0.0","1.5")
axis(2,at = y.axis,labels=Y)

color <- rgb(190, 190, 190, alpha=80, maxColorValue=255)
rect(2005.8,-1.6, 2006.4, 1.6, density = 100, col = color,
     angle = -30, border = "transparent")
     
rect(2007.6, -1.6, 2008.4, 1.6, density = 100, col = color,
     angle = -30, border = "transparent")


###########################################################################
########## Western Europe		###############
###########################################################################

data <- read.csv("UNHCR_Data_08052016.csv", sep=",", header=TRUE)
data <- data[data$region=="Western Europe and Others",]
data <- data[data$candidate==1,]
data <- data[data$losing_candidate!=1,]

myvars <- c("year","latentmean")
data1 <- data[myvars]
data1 <- na.omit(data1)
dim(data)

win2006 <- data1[data1$year==2006,]
win2007 <- data1[data1$year==2007,]
win2008 <- data1[data1$year==2008,]
win2009 <- data1[data1$year==2009,]
win2010 <- data1[data1$year==2010,]
win2011 <- data1[data1$year==2011,]
win2012 <- data1[data1$year==2012,]

w2006 <- mean(win2006$latentmean) 
w2007 <- mean(win2007$latentmean) 
w2008 <- mean(win2008$latentmean) 
w2009 <- mean(win2009$latentmean) 
w2010 <- mean(win2010$latentmean) 
w2011 <- mean(win2011$latentmean) 
w2012 <- mean(win2012$latentmean) 


data <- read.csv("UNHCR_Data_08052016.csv", sep=",", header=TRUE)
data <- data[data$region=="Western Europe and Others",]
data <- data[data$candidate==1,]
data <- data[data$losing_candidate==1,]
myvars <- c("year","latentmean")
data1 <- data[myvars]
data1 <- na.omit(data1)
dim(data)


los2006 <- data1[data1$year==2006,]
los2007 <- data1[data1$year==2007,]
los2008 <- data1[data1$year==2008,]
los2009 <- data1[data1$year==2009,]
los2010 <- data1[data1$year==2010,]
los2011 <- data1[data1$year==2011,]
los2012 <- data1[data1$year==2012,]


l2006 <- mean(los2006$latentmean) 
l2007 <- mean(los2007$latentmean) 
l2008 <- mean(los2008$latentmean) 
l2009 <- mean(los2009$latentmean) 
l2010 <- mean(los2010$latentmean) 
l2011 <- mean(los2011$latentmean) 
l2012 <- mean(los2012$latentmean) 




adjust <- 0.25
y1 <- c(w2006,w2007,w2008,w2009,w2010,w2011,w2012)
x1 <- c(2006:2012)

y2 <- c(l2006,l2007,l2008,l2009,l2010,l2011,l2012)
x2 <- c(2006:2012)


plot(x1,y1,xlab="Election",xlim=c(2006,2012),ylim=c(0,3),pch=19,col="dodgerblue",frame.plot=T,axes=F,ylab="Human Rights Score",main="Western Europe and Others")
points(x2,y2,col="red",pch=4,lwd=5)


x.axis <- c(2006:2012)
X <- c("'06","'07","'08","'09","'10","'11","'12")
axis(1,at = x.axis,labels=X)

y.axis <- c(0,1.5,3)
Y <- c("0.0","1.5","3.0")
axis(2,at = y.axis,labels=Y)

color <- rgb(190, 190, 190, alpha=80, maxColorValue=255)
rect(2005.8,-0.1, 2006.4, 3.1, density = 100, col = color,
     angle = -30, border = "transparent")
     
rect(2006.6,-0.1, 2007.4, 3.1, density = 100, col = color,
     angle = -30, border = "transparent")

rect(2007.6, -0.1, 2008.4, 3.1, density = 100, col = color,
     angle = -30, border = "transparent")

rect(2011.6, -0.1, 2012.2, 3.1, density = 100, col = color,
     angle = -30, border = "transparent")

legend(2007,-1.0, legend=c("Winning Candidates in HRC Election", "Losing Candidates in HRC Election"), pch=c(19,4), col=c("dodgerblue", "red"),horiz=FALSE,bty = "n",pt.cex=c(1,1.5),xpd=NA)


